package com.robot.controller;

import com.robot.dao.dto.CompanyInvitationDTO;
import com.robot.dao.dto.UserUpdateDto;
import com.robot.service.UserService;
import com.robot.common.result.Response;
import io.minio.errors.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;


@RestController
@RequestMapping("/user")
@Slf4j
@Api(tags = "用户相关接口")
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("/addByInvitationCode")
    @ApiOperation("用户根据邀请码关联企业信息")
    public Response addByInvitationCode(@RequestBody CompanyInvitationDTO companyInvitationDTO) {
        userService.addByInvitationCode(companyInvitationDTO);
        return Response.success();
    }



    @PostMapping("/uploadUserImage")
    @ApiOperation("上传用户头像")
    public Response<String> uploadUserImage( @RequestParam("file") MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
       String url= userService.uploadUserImage(file);
       log.info("头像。。。。。。",url);
        return Response.success(url);
    }


    @PostMapping("/modifyUser")
    @ApiOperation("用户信息修改")
    public Response modifyUser(@RequestBody UserUpdateDto userUpdateDto) {
        userService.modifyUser(userUpdateDto);
        return Response.success();
    }

}
